package myJs.cps

import myJs.Implicits._
import myJs.api.Api
import myJs.myPkg.RSelect.SelectOption
import myJs.myPkg.jquery.{$, JQuery}
import myJs.myPkg.reactHookForm.{FieldR, RegisterOptions, UseFormRT, ValidationValueMessage}
import myJs.myPkg._
import org.scalajs.dom.html
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import slinky.core.facade.Hooks.{useEffect, useState}
import slinky.core.facade.{Fragment, React, ReactElement}
import slinky.web.html._

import scala.collection.immutable.SeqMap
import scala.scalajs.js

/**
 * Created by yz on 21/1/2022
 */
@react object PureAsyncRSelectInlineCp {

  case class Props(name: String = "",
                   value: String,
                   onChange: String => Unit,
                   registerOptions: RegisterOptions,
                   useForm: UseFormRT,
                  )

  val component = FunctionalComponent[Props] { props =>

    object FTool {

    }

    val hasErrorCls = if (props.useForm.formState.errors.isDefinedAt(props.name)) "has-error" else ""

    div(className := s"form-group ${hasErrorCls}",
      label(className := "control-label col-sm-2", "样本编号:"),
      div(className := "col-sm-4",
        {
          PureAsyncRSelectCp(useForm = props.useForm, onChange = props.onChange,
            name = "id", value = props.value,
            registerOptions = {
              val info = "样本编号"
              RegisterOptions(
                required = ValidationValueMessage(value = true, message = s"${info}不能为空！"),
              )
            }
          )
        }
      )
    )

  }

}
